package org.zk.dubbo_consumer.controller;


import com.github.pagehelper.PageInfo;
import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageInfo;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.zk.dubbo_consumer.util.*;
import org.zk.entity.Broadcast;
import org.zk.entity.Course;
import org.zk.entity.Teacher;
import org.zk.entity.User;
import org.zk.service.BroadcastService;
import org.zk.service.CourseService;
import org.zk.service.TeacherService;
import org.zk.service.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
 * <p>
 * 前端控制器
 * 高顺
 * </p>
 *
 * @author Alicelonely
 * @since 2019-12-11
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;
    @Resource
    @Getter
    @Setter
    private TeacherService teacherService;

    @Resource
    private BroadcastService broadcastService;

    @Resource
    private CourseService courseService;

    //手机号验证码
    private int verificationCode;

    //邮箱验证码
    private int mailVerificationCode;


    /**
     * 根据typeId获取所有的正在直播和课程的数据
     *
     * @param typeId
     * @return
     */
    @RequestMapping("/getAllBraodcastAndCoueseByTypeId")
    @ResponseBody
    public List getAllBraodcastAndCoueseByTypeId(Integer typeId) {
        Map map = new HashMap();
        map.put("typeId", typeId);
        List list = new ArrayList();
        List<Broadcast> broadcastList = broadcastService.getBraodcastBeingByTypeId(map);
        List<Course> courseList = courseService.getCourseByTypeId(map);
        for (Broadcast broadcast:broadcastList){
            list.add(broadcast);
        }
        for (Course course:courseList){
            list.add(course);
        }
        return list;

    }


    @RequestMapping("/toInformation")
    public ModelAndView toInformation(int userId) {
        User user1 = userService.getAllUser(userId);
        user1.setUserPhone(DESUtil.decryptBasedDes(user1.getUserPhone()));
        ModelAndView mv = new ModelAndView("person/information");
        mv.addObject("list" , user1);
        return mv;
    }

    /**
     * 基本信息修改
     *
     * @param
     */
    @ResponseBody
    @RequestMapping("/editMsg")
    public List updateUser(User user, HttpSession session) {
        List<String> ls = new ArrayList<>();
        User user1= (User) session.getAttribute("user");
        int userId=user1.getUserId();
//        user1.setUserPhone(DESUtil.decryptBasedDes(user.getUserPhone()));
        user.setUserId(userId);
        int result=userService.updateUser(user);
        if (result>0){
            ls.add("success");
        }else {
            ls.add("fail");
        }
        return ls;
    }

    /**
     * 修改头像
     *
     * @param
     */
    @ResponseBody
    @RequestMapping("/editPic")
    public List editPic(@RequestParam("file") MultipartFile file, HttpSession session) {
        List list = new ArrayList();
        User user= (User) session.getAttribute("user");
        int userId=user.getUserId();
        String fileName = file.getOriginalFilename();  // 文件名
        if (!"".equals(fileName)) {
            String suffixName = fileName.substring(fileName.lastIndexOf("."));
            File fileMkdir = new File("E:\\userPhoto");
            if (!fileMkdir.exists()) {
                fileMkdir.mkdir();
            }
            String filePath = fileMkdir.getPath() + "\\";
            fileName = UUID.randomUUID() + suffixName;  //新文件名
            File dest = new File(filePath + fileName);
            try {
                //写入文件
                file.transferTo(dest);
            } catch (IOException e) {
            }
        }
        User user1=new User();
        user1.setUserId(userId);
        user1.setUserPhoto(fileName);
        int result=userService.updateUserPic(user1);
        return list;
    }


//高顺---------------------------------------------------------------------------------------------------------------------------------------------------------------
    /**
     * 登录的时候判断手机号是否已经注册(高顺)
     *
     * @param user
     * @return
     */
    @RequestMapping("/phoneIsRegYesOrNo")
    @ResponseBody
    public Map phoneIsRegYesOrNo(User user) {
        Map map = new HashMap();
        user.setUserPhone(DESUtil.encryptBasedDes(user.getUserPhone()));
        User user1 = userService.selectByPhone(user);
        if (user1 != null) {
            map.put("msg", "ok");
        } else {
            map.put("msg", "该手机号还未注册");
        }
        return map;
    }

    /**
     * 用户输入手机号后，如果输入的是未曾注册过的，那就销毁所有的session，防止页面在关闭后在用户名称那里出现空的名字   （高顺）
     *
     * @param session
     * @return
     */
    @RequestMapping("/clearSessionAndToIndex")
    public ModelAndView clearSessionAndToIndex(HttpSession session) {
        session.removeAttribute("user");
        session.removeAttribute("teacher");
        return new ModelAndView("index");
    }

    /**
     * 采用DES加密用户登录   （高顺）
     *
     * @param password
     * @param gphone
     * @param request
     * @return
     */
    @RequestMapping("/phoneLoginDes")
    @ResponseBody
    public Map phoneLoginDes(String password, String gphone, HttpServletRequest request, Model model) {
        Map map = new HashMap();
        HttpSession session = request.getSession(true);   //用HTTPSession需写这句
        boolean result = PhoneOrMail.isPhoneOrMail(gphone);
//        String jmphone = DESUtil.encryptBasedDes(gphone);    //加密后的邮箱或手机号
//        String jmPwd = DESUtil.encryptBasedDes(password);      //加密后的密码
        User user11 = new User();

        try {
            UsernamePasswordToken token = new UsernamePasswordToken(gphone, password);
            Subject subject = SecurityUtils.getSubject();
            subject.login(token);
            user11 = (User) subject.getPrincipal();

            if (user11 != null) {
                session.setAttribute("user", user11);
                System.out.println("名字="+user11.getUserName());
                map.put("user", user11);
                String pp = user11.getUserPhone().replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
                session.setAttribute("pp", pp);
                map.put("msg", "ok");
            } else {
                map.put("msg", "该用户没有注册!");
            }

        } catch (Exception e) {
            map.put("msg", "登录失败!");
        }



        return map;
    }

    /**
     * 登陆成功后指向的控制器，得到
     *
     * @param model
     * @return
     */
    @RequestMapping("/index2")
    @RequiresRoles(value = {"SUPERADMINISTATOR"}, logical = Logical.OR)//shiro的角色注解，调用权限方法，对比角色是否符合访问要求
//    @RequiresPermissions(value = {"/rolesPage"})//shiro的权限注解，调用权限方法，对比权限是否符合访问要求
    public ModelAndView loginSuccessMessage(Model model) {
        System.out.println("____________到index了---------------");
        String username = "未登录";//默认值为未登录
        User currentLoginUser = RequestUtils.currentLoginUser();
        if (currentLoginUser != null && StringUtils.isNotEmpty(currentLoginUser.getUserName())) {//判断返回值不为空，且返回数据中的姓名是否为空
            username = currentLoginUser.getUserName();
        } else {
            return new ModelAndView("index");
        }
        model.addAttribute("username", username);
        return new ModelAndView("index");
    }


    /**
     * 被踢掉后的操作  （高顺）
     *
     * @return
     */
    @RequestMapping("/kickout")
    public ModelAndView kickOut() {
        return new ModelAndView("gs_login/kickout");
    }


    /**
     * /登录后去拿phoneLogin存在session的user显示在登录那块的名称（高顺）
     *
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/getSession")
    public Map getSession(HttpServletRequest request) {
        HttpSession session = request.getSession(true);   //用HTTPSession需写这句
        User user = (User) session.getAttribute("user");
        Map map = new HashMap();
        map.put("user", user);
        //判断vip到期
        if (user != null) {
            if (user.getUserVipdue() != null) {

                long due = user.getUserVipdue().getTime();
                System.out.println("=================" + user.getUserVipdue().getTime());
                System.out.println("=======" + user.getUserId() + "=========");
                if (due < new Date().getTime()) {
                    user.setUserVip(0);
                    userService.updateUserVip(user.getUserId());
                }
            }
        } else {
            try {

            } catch (Exception e) {

            }
        }
        return map;
    }

    /**
     * 注册时向手机发送验证码（高顺）
     *
     * @param userPhone
     * @param model
     * @return
     */
    @ResponseBody
    @RequestMapping("/regUserHqYzm")
    public ModelAndView hqdx(String userPhone, Model model, HttpSession session) {
//        HttpSession session = request.getSession(true);   //用HTTPSession需写这句
        boolean result = PhoneOrMail.isPhoneOrMail(userPhone);
        if (result == true) {
            mailVerificationCode = MailUtil.sendMail(userPhone);
            session.setAttribute(userPhone + "ph", new Date());
            session.setAttribute(userPhone, verificationCode);
            System.out.println("mailVerificationCode=" + mailVerificationCode);
            return new ModelAndView("gs_login/loginAndReg");
        } else {
            verificationCode = YunPianSend.ypsend(userPhone); //云片
//            verificationCode = DxUtil.send(userPhone);      //互亿无线
            session.setAttribute(userPhone + "ph", new Date());
            session.setAttribute(userPhone, verificationCode);
            System.out.println("verificationCode=" + verificationCode);
            return new ModelAndView("gs_login/loginAndReg");
        }
    }

    /**
     * 注册时向手机发送验证码（高顺）
     *
     * @param userPhone
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/regUserHqYzm2")
    public ModelAndView hqdx2(String userPhone, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Teacher teacher = (Teacher) session.getAttribute("teacher");
        if (user != null) {
            userPhone = user.getUserPhone();
        } else {
            userPhone = teacher.getTeacherPhone();
        }
        verificationCode = YunPianSend.ypsend(userPhone); //云片
        session.setAttribute(userPhone + "ph", new Date());
        session.setAttribute(userPhone,verificationCode);
        System.out.println("verificationCode=" + verificationCode);
        return new ModelAndView("gs_login/changePhoneNumber.html");
    }


    /**
     * 忘记密码时向手机或邮箱发送验证码（高顺）
     *
     * @param userPhone
     * @param model
     * @return
     */


    @ResponseBody
    @RequestMapping("/forgetThePassword")
    public ModelAndView forget(String userPhone, Model model, HttpServletRequest request) {
        HttpSession session = request.getSession(true);   //用HTTPSession需写这句
        session.setAttribute("phone", userPhone);
        boolean answer = PhoneOrMail.isPhoneOrMail(userPhone);
        if (answer == true) {
            mailVerificationCode = MailUtil.sendMail(userPhone);
            session.setAttribute(userPhone,mailVerificationCode);
            System.out.println("mailVerificationCode=" + mailVerificationCode);
            return new ModelAndView("gs_login/forgetPwd1");
        } else {
            verificationCode = YunPianSend.ypsend(userPhone); //云片
//            verificationCode = DxUtil.send(userPhone);      //互亿无线
            System.out.println("verificationCode=" + verificationCode);
            model.addAttribute("verificationCode", verificationCode);
            session.setAttribute(userPhone,verificationCode);
            return new ModelAndView("gs_login/forgetPwd1");
        }
    }

    /**
     * 判断验证码的正确性（高顺）
     * DES加密手机号加注册
     */
    @RequestMapping("/comparecode")
    @ResponseBody
    public int authorization(String code, String userPhone, String userName, String userPwd, HttpSession session) {
        int flag;
//        HttpSession session = request.getSession(true);
//        String autocode= (String) session.getAttribute("verificationCode");
        //验证码不为空时，到后台进行比较，返回响应码，为1，提示请先获得验证码
        //为2，提示验证码错误
        //为3，验证码正确，无提示

        String mvc = String.valueOf(mailVerificationCode);      //邮箱验证码
        Date sendTime = (Date) session.getAttribute(userPhone + "ph");
        Date finishDate = new Date();
        int code1 = (int) session.getAttribute(userPhone);  //获取session存的验证码
        String code2=String.valueOf(code1);
        String autocode = String.valueOf(code);     //用户输入的手机号验证码
        long aa = DateUtil.betweenMs(sendTime, finishDate);//相差毫秒数
        if (aa / 1000 < 60) {
            if (code2.equals(autocode) || code2.equals(mvc)) {
                String jmphone = DESUtil.encryptBasedDes(userPhone);    //加密后的邮箱或手机号
                String jmPwd = DESUtil.encryptBasedDes(userPwd);      //加密后的密码

                boolean result = PhoneOrMail.isPhoneOrMail(userPhone);  //调用判断手机号或者邮箱的方法
                User user = new User();
                User user1 = new User();
                if (result == true) {  //等于true时是邮箱

                    user.setUserEmail(jmphone);
                    user.setUserName(userName);
                    user.setUserPwd(jmPwd);
                    userService.insertUserByEmail(user);
                } else {        //等于false是手机号
                    user.setUserPhone(jmphone);
                    user.setUserName(userName);
                    user.setUserPwd(jmPwd);
                    userService.insertUserByPhone(user);
                }
                flag = 3;
                session.removeAttribute(userPhone); //消除session
                return flag;
            }
            flag = 2;
        } else {
            flag = 2;
        }
        return flag;
    }

    /**
     * 判断验证码是否正确（高顺）
     *
     * @param code
     * @param userPhone
     * @param session
     * @return
     */
    @RequestMapping("/verificationCode")
    @ResponseBody
    public int verificationCode(String code, String userPhone, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Teacher teacher = (Teacher) session.getAttribute("teacher");
        if (user != null) {
            userPhone = user.getUserPhone();
        } else {
            userPhone = teacher.getTeacherPhone();
        }
        int code1 = (int) session.getAttribute(userPhone);
        String code2=String.valueOf(code1);
        String verificationCode1 = String.valueOf(code);
        Date sendTime = (Date) session.getAttribute(userPhone + "ph");
        Date finishDate = new Date();
        long aa = DateUtil.betweenMs(sendTime, finishDate);//相差毫秒数
        int flag = 0;
        if (aa / 1000 < 60 && verificationCode1 == code2 || code2.equals(verificationCode1)) {
            flag = 3;
            session.removeAttribute(userPhone);
        } else {
            flag=2;
        }
        return flag;
    }


    /**
     * 判断数据库中是否有这个手机号（高顺）
     */
    @RequestMapping("/fgt")
    @ResponseBody
    public int fgp(String userPhone, String code,HttpSession session) {
//        String autocode = String.valueOf(verificationCode);     //手机号验证码
//        String mvc = String.valueOf(mailVerificationCode);      //邮箱验证码
        int code1= (int) session.getAttribute(userPhone);
        String code2=String.valueOf(code1);
        User user1 = new User();
        User user = new User();
        int redd = 0;
        if (code.equals(code2) || code.equals(code2)) {
            String jmphone = DESUtil.encryptBasedDes(userPhone);    //加密后的邮箱或手机号
            boolean result = PhoneOrMail.isPhoneOrMail(userPhone);
            if (result == true) {
                user.setUserEmail(jmphone);
                user1 = userService.selectForGetByEmail(user);

                session.removeAttribute(userPhone);
            } else {
                user.setUserPhone(jmphone);
                user1 = userService.selectForGetByPhone(user);

                session.removeAttribute(userPhone);
            }
            if (user1 != null) {
                redd = 3;
                return redd;
            } else {
                redd = 2;
                return redd;
            }
        }
        return redd;
    }

    /**
     * 判断手机号跟登录的是不是一样（高顺）
     *
     * @param userPhone
     * @param session
     * @param
     * @param msg
     * @return
     */
    @RequestMapping("/phoneRightAndWrong")
    @ResponseBody
    public String phoneRightAndWrong(String userPhone, HttpSession session, String msg) {
        User user = (User) session.getAttribute("user");
        Teacher teacher = (Teacher) session.getAttribute("teacher");

        if (user != null) {
            String userPhone2 = user.getUserPhone();
            if (userPhone.equals(userPhone2)) {
                msg = "0";
            } else {
                msg = "1";
            }
        } else if (teacher != null) {
            String teacherPhone = teacher.getTeacherPhone();
            if (userPhone.equals(teacherPhone)) {
                msg = "0";
            } else {
                msg = "1";
            }
        }
        return msg;

    }


    /**
     * 去修改手机号中的填写要修改的手机号页面，但是要先判断这个账号的安全性（高顺）
     *
     * @return
     */
    @RequestMapping("/toChangePhoneNumberFillIn")
    @ResponseBody
    public Map toChangePhoneNumberFillIn(String userPwd, HttpSession session, String msg) {
        User user = (User) session.getAttribute("user");
        Teacher teacher = (Teacher) session.getAttribute("teacher");
        User user1 = new User();
        User user2 = new User();
        Teacher teacher1 = new Teacher();
        Teacher teacher2 = new Teacher();
        if (user != null) {
            String userPhone = DESUtil.encryptBasedDes(user.getUserPhone());
            String userPWd = DESUtil.encryptBasedDes(userPwd);
            user1.setUserPhone(userPhone);
            user1.setUserPwd(userPWd);
            user2 = userService.getUserLogin(user1);
            if (user2 != null) {
                msg = "0";  //0为user表有
            } else {
                msg = "1";    //1为user表没有
            }
        } else if (teacher != null) {
            String userPhone = DESUtil.encryptBasedDes(teacher.getTeacherPhone());
            String userPWd = DESUtil.encryptBasedDes(userPwd);
            teacher1.setTeacherPhone(userPhone);
            teacher1.setTeacherPwd(userPWd);
            teacher2 = teacherService.getTeacherLogin(teacher1);
            if (teacher2 != null) {
                msg = "0";  //0为teacher表有
            } else {
                msg = "1";    //1为teacher表没有
            }
        }
        Map map = new HashMap();
        map.put("msg", msg);
        return map;


    }

    /**
     * 去修改2页面（高顺）
     *
     * @return
     */
    @RequestMapping("/toChangePhone")
    public ModelAndView toChangePhone() {
        return new ModelAndView("gs_login/changePhoneNumber_fill_in.html");
    }


    /**
     * 修改手机号(讲师用户都修改)（高顺）
     *
     * @param
     * @param userPhone
     * @param session
     * @return
     */
    @RequestMapping("/updatePhone")
    public ModelAndView updatePhone(String userPhone, User user, HttpSession session, Teacher teacher) {
        User user1 = (User) session.getAttribute("user");
        Teacher teacher1 = (Teacher) session.getAttribute("teacher");
        String userPhone1 = DESUtil.encryptBasedDes(userPhone);
        if (user1 != null) {      //得同时考虑普通用户和讲师
            if (user1.getUserSign() == 1) {
                user.setUserPhone(userPhone1);
                user.setUserId(user1.getUserId());
                userService.updateUserPhone(user);
                teacher.setTeacherPhone(userPhone1);
                teacher.setTeacherId(teacher1.getTeacherId());
                teacherService.updateTeacherPhone(teacher);
                session.removeAttribute("user");
            } else {
                user.setUserPhone(userPhone1);
                user.setUserId(user1.getUserId());
                userService.updateUserPhone(user);
                session.removeAttribute("user");
            }
        } else {
            user.setUserPhone(userPhone1);
            user.setUserId(teacher1.getUser().getUserId());
            userService.updateUserPhone(user);
            teacher.setTeacherPhone(userPhone1);
            teacher.setTeacherId(teacher1.getTeacherId());
            teacherService.updateTeacherPhone(teacher);
            session.removeAttribute("teacher");
        }
        return new ModelAndView("gs_login/changePhoneNumber3.html");
    }

    /**
     * 修改密码(讲师用户都修改)（忘记密码）（高顺）
     *
     * @param userPwd
     * @param userPhone
     * @param session
     * @return
     */
    @RequestMapping("/updatePwd")
    public ModelAndView updatePwd(String userPwd, String userPhone, HttpSession session, User user, Teacher teacher) {
        String userPhone1 = DESUtil.encryptBasedDes(userPhone);
        user.setUserPhone(userPhone1);
        User user2 = userService.selectForGetByPhone(user);   //通过手机号去查所对应的全部内容，将用来根据user表中的状态去决定修不修改teacher表的密码
        String userPwd1 = DESUtil.encryptBasedDes(userPwd);
        boolean result = PhoneOrMail.isPhoneOrMail(userPhone);
        int answer = 0;
        User user1 = new User();
        if (result) {
            user1.setUserEmail(userPhone1);
            user1.setUserPwd(userPwd1);
            answer = userService.updatePwdByEmail(user1);
        } else {
            if (user2.getUserSign().equals("1")) {
                teacher.setTeacherPhone(userPhone1);
                teacher.setTeacherPwd(userPwd1);
                teacherService.updatePwdByPhone(teacher);
                user1.setUserPhone(userPhone1);
                user1.setUserPwd(userPwd1);
                answer = userService.updatePwdByPhone(user1);
            } else {
                user1.setUserPhone(userPhone1);
                user1.setUserPwd(userPwd1);
                answer = userService.updatePwdByPhone(user1);
            }

        }
        if (answer == 1) {
            session.removeAttribute("phone");

            return new ModelAndView("gs_login/forgetPwd3.html");
        } else {
            return new ModelAndView("gs_login/forgetPwd2.html");
        }
    }

    /**
     * 去修改手机号的页面（高顺）
     *
     * @return
     */
    @RequestMapping("/toChangePhoneNumber")
    public ModelAndView toChangePhoneNumber() {
        return new ModelAndView("gs_login/changePhoneNumber.html");
    }

    /**
     * 点击讲师入驻的时候判断用户是否是登录状态（高顺）
     *
     * @param request
     * @return
     */
    @RequestMapping("/lecturerEnter")
    @ResponseBody
    public List lecturerEnter(HttpServletRequest request) {
        List list = new ArrayList();
        HttpSession session = request.getSession(true);   //用HTTPSession需写这句
        User user = (User) session.getAttribute("user");
        if (user != null) {
            list.add("ok");
        } else {
            list.add("请登录");
        }
        return list;
    }

    /**
     * 根据手机号或邮箱查（用来检查这个用户是否已经注册）(高顺)
     *
     * @param
     * @return
     */
    @RequestMapping("/selectPhoneOrEmail")
    @ResponseBody
    public List selectPhoneOrEmail(String userPhone, Map map) {
        List list = new ArrayList();
        User user = new User();
        String userPhone1 = DESUtil.encryptBasedDes(userPhone);
        user.setUserPhone(userPhone1);
        String msg = "";
        User user1 = userService.selectByPhone(user);
        if (user1 != null) {
            list.add("1");
        } else {
            list.add("2");
        }
        return list;
    }

    /**
     * 判断完用户是登录状态的时候就让它进去申请讲师入驻的页面 （高顺）
     *
     * @return
     */
    @RequestMapping("/toApplyTeacher")
    public ModelAndView toApplyTeacher() {
        return new ModelAndView("user/applyTeacher");
    }


    //访问主页（高顺）
    @RequestMapping("/toIndex")
    @ResponseBody
    public ModelAndView toIndex(HttpServletRequest request) {
        return new ModelAndView("index.html");
    }

    /**
     * 退出（消除所有session）
     *
     * @param request
     * @return
     */
    @RequestMapping("/toIndexUpdatePhone")
    public String toIndexUpdatePhone(HttpServletRequest request) {
        Enumeration em = request.getSession().getAttributeNames();        //得到session中所有的属性名
        while (em.hasMoreElements()) {
            request.getSession().removeAttribute(em.nextElement().toString());  //循环删除
        }
        return "redirect:toIndex";
    }

    //登录界面的弹窗（高顺）
    @RequestMapping("/loginAndRed")
    public ModelAndView loginAndReg() {
        return new ModelAndView("gs_login/loginAndReg.html");
    }

    //忘记密码页面1（高顺）
    @RequestMapping("/forgetpwd")
    public ModelAndView forgetpwd() {
        return new ModelAndView("gs_login/forgetPwd1.html");
    }

    //忘记密码页面2（高顺）
    @RequestMapping("/forget2")
    public ModelAndView forget2() {
        return new ModelAndView("gs_login/forgetPwd2.html");
    }

    //高顺---------------------------------------------------------------------------------------------------------------------------------------------------------------


//
//@RequestMapping("/toReg")
//public ModelAndView demo2(){
//        return new ModelAndView("gs_login/reg.html");
//}
//    @RequestMapping("/toLoginH")
//    public ModelAndView toLoginH(){
//        return new ModelAndView("gs_login/login1.html");
//    }

//高顺---------------------------------------------------------------------------------------------------------------------------------------------------------------


    /**
     * 高申，用户列表展示
     */
    @RequestMapping("/toUserList")
    public ModelAndView toUserList(){
        return new ModelAndView("user/userList");
    }

    /**
     * 用户列表展示，分页处理
     * @param pageSize
     * @param pageNum
     * @return
     */
    @RequestMapping("/getAllUser")
    public Map getAllUser(int pageSize, int pageNum, String userName, String userGender, String userPhone, String userVip) {

        Map<String, Object> maps = new HashMap<>();
        maps.put("pageSize", pageSize);
        maps.put("pageNum", pageNum);

        //多条件查询数据传入
        if (userName != null && userName.length() > 0) {
            maps.put("userName", userName);
        }
        if (userGender != null && userGender.length() > 0) {
            if ("女".equals(userGender)) {
                maps.put("userGender", 0);
            }
            if ("男".equals(userGender)) {
                maps.put("userGender", 1);
            }
        }
        if (userPhone != null && userPhone.length() > 0) {
            maps.put("userPhone", DESUtil.encryptBasedDes(userPhone));
        }
        if (userVip != null && userVip.length() > 0) {
            if (userVip.contains("v") || userVip.contains("V")) {
                maps.put("userVip", 1);
            } else {
                maps.put("userVip", 0);
            }
        }


        PageInfo page = userService.getlookAllUserPage(maps);
        maps.put("page", page);
        maps.put("totalPage", page.getPages());
        List<User> ls = page.getList();
        for (int i = 0; i < ls.size(); i++) {
            String getPhone = ls.get(i).getUserPhone();
            ls.get(i).setUserPhone(DESUtil.decryptBasedDes(getPhone));
        }
        return maps;
    }

    /**
     * 添加用户(弹框)
     */
    @RequestMapping("/toUserAdd")
    public ModelAndView toUserAdd() {
        return new ModelAndView("user/userAdd");
    }

    /**
     * 异步判断添加用户输入的手机号是否存在
     */
    @RequestMapping("/checkPhone")
    public Map checkPhone(String userPhone) {
        String strPhone = DESUtil.encryptBasedDes(userPhone);
        Map<String, Object> maps = new HashMap<>();
        int num = userService.checkPhone(strPhone);
        if (num > 0) {
            maps.put("msg", 0);
        } else {
            maps.put("msg", 1);
        }
        return maps;
    }

    //添加用户
    @RequestMapping("/addUser")
    public Map startAddUser(User user) {
        System.out.println(user);
        user.setUserPhone(DESUtil.encryptBasedDes(user.getUserPhone()));
        userService.insertUserStart(user);
        Map<String,Object> maps=new HashMap<>();
        maps.put("msg",1);
        return maps;
    }

    //跳转到编辑用户
    @RequestMapping("/toUserEdit")
    public ModelAndView toUserEdit(int userId) {
        User user = userService.getUserInfoById(userId);
        user.setUserPhone(DESUtil.decryptBasedDes(user.getUserPhone()));//手机号解密
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("user", user);
        modelAndView.setViewName("user/userEdit");
        return modelAndView;
    }

    //接收编辑页面的数据
    @RequestMapping("/userEdit")
    public void userEdit(User user) {
        user.setUserPhone(DESUtil.encryptBasedDes(user.getUserPhone()));//手机号解密
        userService.updateUserEdit(user);
    }

    //删除用户
    @RequestMapping("/delUser")
    public void delUserById(User user) {
        userService.delUserById(user);
    }

    //禁用用户
    @RequestMapping("/unUser")
    public void unUserById(User user){
        userService.updateUserById(user);
    }



    /**
     * 钱东升
     * @return
     */
    @RequestMapping("toIndex3")
    public ModelAndView toAddCourse() {
        return new ModelAndView("/index3");
    }



    /**
     * 根据id查询VIP用户
     *
     * @return
     */
    @RequestMapping("/getVipId")
    public ModelAndView getLessionById() {
        ModelAndView modelAndView = new ModelAndView("admin/viplist");
        return modelAndView;
    }
    //跳转到发布通知界面
    @RequestMapping("/toNotice")
    public ModelAndView getonById() {
        ModelAndView modelAndView = new ModelAndView("admin/notice");
        return modelAndView;
    }


    /**
     * 后台分页显示所有vip会员
     *模糊查询
     * 刘硕
     * @return
     */
    @RequestMapping("/getVipList")
    @ResponseBody
    public Map getVipList(int pageSize, int pageNum,String userName ) {

        Map<String, Object> map = new HashMap<>();
        User user=new User();
        user.setUserVip(1);
        map.put("user", user);
        map.put("pageSize", pageSize);
        map.put("pageNum", pageNum);
        map.put("userName",userName);
        PageInfo page =userService.getVipUser(map);
        map.put("page",page);
        map.put("pages",page.getPages());
        map.put("total",page.getTotal());
        return map;
    }

    /**
     * 后台对vip用户的操作（刘硕）
     * @param
     * @return
     */
    @RequestMapping("/jinyong")
    @ResponseBody
    public Map jinyong(Integer userId) {

        Map<String, Object> map = new HashMap<>();
        User user=new User();
        user.setUserState(1);
        map.put("user", user);
        System.out.println("================="+userId);
        userService.updateUserState(userId);

        return map;
    }
    @RequestMapping("/qiyong")
    @ResponseBody
    public Map qiyong(Integer userId) {
        Map<String, Object> map = new HashMap<>();
        User user=new User();
        user.setUserState(0);
        map.put("user", user);
        System.out.println("================="+userId);
        userService.updateUserQiYong(userId);

        return map;
    }

}

